﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.TextEditor.Document;

namespace SysSUFront
{
    internal enum Mode { PUT, QUERY }

    internal partial class TupleDefinitionForm : UserControl
    {
        private const string RESTRICTION_DEFAULT = "function restrict(tuple) {\r\n    return true;\r\n}";
        private const string TUPLE_DEFAULT = "{}";

        private Mode mode;

        public Mode Mode 
        {
            set 
            {
                mode = value;
                if (mode == Mode.PUT)
                {
                    lblInput.Text = "Tuple:";
                    tbxRestriction.Enabled = false;                    
                }
                else if (mode == Mode.QUERY)
                {
                    lblInput.Text = "Pattern:";
                    tbxRestriction.Enabled = true;                    
                }
            }
            get { return mode; }
        }

        public string Tuple 
        {
            get { return tbxTuplePattern.Text; }
            set { tbxTuplePattern.Text = value; }
        }

        public string Restriction
        {
            get { return tbxRestriction.Text; }
            set { tbxRestriction.Text = value; }
        }

        public TupleDefinitionForm()
        {
            InitializeComponent();
        }

        private void TupleDefinitionForm_Load(object sender, EventArgs e)
        {
            tbxTuplePattern.Document.HighlightingStrategy =
                HighlightingStrategyFactory.CreateHighlightingStrategy("JavaScript");
            tbxRestriction.Document.HighlightingStrategy =
               HighlightingStrategyFactory.CreateHighlightingStrategy("JavaScript");

            Clear();
        }

        public void Clear()
        {
            tbxTuplePattern.Text = TUPLE_DEFAULT;
            tbxRestriction.Text = RESTRICTION_DEFAULT;
        }
    }
}
